package com.dule.Medic.pages;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.dule.Medic.model.Doctor;
import com.dule.Medic.model.Patient;
import com.dule.Medic.service.PatientService;

public class ChangePatientInfo
{

	@SuppressWarnings("unused")
	@Property      
	@SessionState
	private Doctor doctor;    
	private boolean doctorExists;          
	
	@Persist("flash") 
	@Property
	private Patient patient;

	
	@InjectPage  
	private ListPatients listPatients;   
	
	
	@Inject       
	private PatientService patientservice;    
	
	public Object onActivate(Long Id)
	{      
		if(doctorExists)
		{    
			patient=patientservice.retrieveOne(Id);
			return null; 
			
		}          
		return FirstPage.class;   
	}
	
	
	@OnEvent(component="patientUpdate") 
	public Object update()
	{       
		boolean changed=patientservice.update(patient);  
		if(changed)
		{                       
			return listPatients;  
		}         
		else
		{      
			return this;     
		}    
	}  
	
	


}
